<!DOCTYPE html>
<html style="background: #ea3c13!important">
<head lang="en">
<meta charset="UTF-8">
<meta name='apple-touch-fullscreen' content='yes'>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta content="fullscreen=yes,preventMove=no" name="ML-Config">
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telephone=no,email=no,address=no"/>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
<title>西海良品</title>
<link rel="stylesheet" href="/style/lh/css/style.css?ver=20190421">
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css?ver=20190402">
<script src="/style/lh/js/style.js"></script>
<script src="/style/new/js/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="/style/js/sweet-alert.min.js?ver=20190402"></script>
<script type="text/javascript">
(function () {
var b = document.documentElement,
a = function () {
    var a = b.getBoundingClientRect().width;
    b.style.fontSize = (a / 1080) * 100+ "px";
}, c = null;
window.addEventListener("resize", function () {
clearTimeout(c);
c = setTimeout(a, 300);
});
a();
})();
</script>
<style type="text/css">
.popmask{position: fixed;left:0; top:0;width:100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1; display: none;}
.popslk{position: fixed;width: 90%; left: 5%; height: 50%; top:25%; z-index: 2; background: #fff; border-radius: .2rem; display: none;}
.popslk .bottom{width: 100%; height: auto; bottom: .5rem; position: relative; text-align: center;}
.popslk .bottom a{padding: .2rem .8rem; border-radius: .5rem; width:1rem; height: .5rem; line-height: .5rem; color: #fff; font-size: .4rem; background: #666;}
</style>
</head>
<body>
<div class="m-bg">
    <div class="m-img">
        <img src="/style/lh/images/mLogo.png" alt="" class="m-Logo">
        <img src="/style/lh/images/mTitle.png" alt="" class="m-Title">
    </div>
    <div class="m-content">
        <h2>升级代理</h2>
        <h3 class="m-content-h3">UPGRADE  AGENT</h3>
        <h4 class="m-content-h4"></h4>
        <ul class="m-list">            
            
          <?php if($this->data['agent_level'] <2){?>
            <li>
                <img src="/style/lh/images/micon2.png" alt="" class="mList-left" >
                <div class="mList-right">
                    <div class="main-left">
                        <h3>县代</h3>
                        <h4>GENERAL AGENT</h4>
                    </div>
                    <a href="javascript:_choose(2)" class="main-right">升级</a>
                </div>
            </li>
            <?php }?>
            
            <?php if($this->data['agent_level'] <3){?>
            <li>
                <img src="/style/lh/images/micon3.png" alt="" class="mList-left" >
                <div class="mList-right">
                    <div class="main-left">
                        <h3>市代</h3>
                        <h4>PARTNER</h4>
                    </div>
                    <a href="javascript:_choose(3)" class="main-right">升级</a>
                </div>
            </li>
            <?php }?>
            
          <?php if($this->data['agent_level'] <4){?>
            <li>
                <img src="/style/lh/images/micon4.png" alt="" class="mList-left" >
                <div class="mList-right">
                    <div class="main-left">
                        <h3>省代</h3>
                        <h4>DIRECTOR</h4>
                    </div>
                    <a href="javascript:_choose(4)" class="main-right">升级</a>
                </div>
            </li>
            <?php }?>
        </ul>
    </div>

</div>

<div class="popmask"></div>
<div class="popslk">
    <div class="m-content">
        <h2>选择产品</h2>
        <h3 class="m-content-h3">SELECT PRODUCT</h3>
        <h4 class="m-content-h4"></h4>
        <ul class="m-list">
            <li>                
                <div class="mList-right p100">
                    <div class="main-left">
                        <h3>肽之初</h3>
                        <h4>数量 5</h4>
                    </div>
                    <a href="javascript:upgrade(4)" class="main-right">选择</a>
                </div>
            </li>
            <li>                
                <div class="mList-right p100">
                    <div class="main-left">
                        <h3>肽之初</h3>
                        <h4>数量 3</h4>
                        <h3>肽年轻面膜</h3>
                        <h4>数量 7</h4>
                    </div>
                    <a href="javascript:upgrade(4)" class="main-right">选择</a>
                </div>
            </li>
        </ul>        
    </div>
    <div class="bottom"><a href="javascript:_cancel();">取消</a></div>
</div>

<script type="text/javascript">
var uid = <?=empty($this->data['uid'])?0:$this->data['uid'];?>,
_agent_level = <?=$this->data['agent_level'];?>,
_m = {2:"县代",3:"市代",4:"省代"},
_t = 0;

function _choose(t)
{
    

    $.post("/stock/ajax",
    {
        "act":"getsetting",
        "uid":uid,
        "old_agent_level":_agent_level,
        "agent_level":t,
        "mr":Math.random()
    },function(json){
        console.log(json);
        if(json.code == 200)
        {
            _t = t;
            $(".popmask,.popslk").css("display","block");

            $(".popslk .m-list").html('');

            $.each(json.data,function(settingId,da){
                $(".popslk .m-list").append('<li id="stid'+settingId+'"><div class="mList-right p100"><div class="main-left"></div><a href="javascript:upgrade('+settingId+')" class="main-right">选择</a></div></li>');

                $.each(da,function(id,arr){
                    if(arr['id']!="")
                    {
                        $("#stid"+settingId+" .main-left").append('<h3>'+json.goods[arr['id']]+'</h3><h4>数量 '+arr['number']+'</h4>');
                    }
                })
            });

        }
        else
        {
            swal("没有相关产品");
        }


    },"json");
}

function _cancel()
{
    $(".popmask,.popslk").css("display","none");
    _t = 0;
}

function upgrade(settingId) {
    if (uid > 0 && settingId > 0) {
        swal({
            title: "确定选择产品并升级 " + _m[_t] + " 吗？",
            type: "warning",
            timer: 30000,
            showCancelButton: true,
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: true
        }, function(isConfirm) {
            if (isConfirm) {
                $.ajax({
                    type: 'post',
                    url: '/user/ajax',
                    data: {
                        'act': 'save_upgrade',
                        'uid': uid,
                        'settingId':settingId,
                        'type': _t,
                        mr: Math.random(),
                    },
                    dataType: 'json',
                    success: function(data) {
                        console.log(data);
                        if (data.code == 200) {
                            swal(data.msg, false, "success");
                            setTimeout(function() {
                                window.location.href = "/user/recommend";
                            }, 2000);
                        } else {
                            swal(data.msg + "[" + data.code + "]", false, "error");
                        }
                    }
                });
            }
        });
    }
}
</script>
</body>
</html>